﻿using System;
using System.Collections.Generic;
using System.Text;
using jade.core;
using System.Windows.Forms;
using MarketSimulator.UI;
using MarketSimulator.Utils.Maps;

namespace MarketSimulator.UI.Assistant
{
    public class AssistantAgent : Agent
    {
        private Action<string> actorsChat;

        private MainForm TheForm;

        public override void setup()
        {
            try
            {
                object[] args = getArguments();
                TheForm = args[0] as MainForm;
                actorsChat = args[1] as Action<string>;
                TheForm.RegisterAssistant(this);

                TheForm.Invoke(actorsChat, "Assistant Agent Created...");
            }
            catch (Exception ex)
            {
                TheForm.Invoke(actorsChat, ex.Message);
            }

        }

        public void WriteToChat(string message)
        {
            TheForm.Invoke(actorsChat, message);
        }

        public void Sell(string poductName, int quantity)
        {
            WriteToChat("Assistant wants to sell " + poductName + Environment.NewLine);
            //Add Behavior Section
            addBehaviour(new GetBestSellPriceBehavior(poductName, quantity, this));
        }

        public void Buy(string poductName, int quantity, City destinationCity)
        {
            WriteToChat(string.Format("Assistant wants to buy {0} of {1} and deposit in {2}.{3}", quantity, poductName, destinationCity, Environment.NewLine));
            //Add Behavior Section
            addBehaviour(new GetBestPriceBuyBehavior(poductName, quantity, destinationCity, this));
        }

    }
}
